package ru.budget.mobile.domain.usecase.consumption

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import ru.budget.mobile.core.Response
import ru.budget.mobile.core.ResponseStates
import ru.budget.mobile.domain.entities.ConsumptionDomain
import ru.budget.mobile.domain.repository.ConsumptionRepository
import ru.budget.mobile.ui.entities.ConsumptionUI

class AddConsumptionUseCase(
    private val repository: ConsumptionRepository
) {

    operator fun invoke(consumption: ConsumptionUI): Flow<Response<Boolean>> = flow {
        emit(Response.Loading(state = ResponseStates.LOADING))
        emit(
            repository.addConsumption(
                consumption = ConsumptionDomain(
                    id = consumption.id,
                    title = consumption.title,
                    type = consumption.type,
                    category = consumption.category,
                    sum = consumption.sum,
                    datetime = consumption.datetime
                )
            )
        )
    }
}